package com.traffic.fuwu.controller;

import com.traffic.fuwu.service.LineService;
import com.traffic.fuwu.vo.VoStatus;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.support.nativejdbc.OracleJdbc4NativeJdbcExtractor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by pikewei on 2017/2/10.
 */
@Controller
@RequestMapping("/line")
public class LineController {
    private static final Logger log = LoggerFactory.getLogger(LineController.class);
    private static final VoStatus voStatus = new VoStatus();

    @Autowired
    private LineService lineService;

    @RequestMapping("/addLine")
    public Map<String, Object> addLine(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        try {
            do {
                // 1.获取请求参数
                String appKey = request.getParameter("appKey"); //企业唯一标识
                String lineCode = request.getParameter("lineCode"); //线路编号
                String lineNo = request.getParameter("lineNo"); //线路自编号(关联Line)
                String lineName = request.getParameter("lineName"); //线路名
                String lineShort = request.getParameter("lineShort"); //线路短号
                String gpsCode = request.getParameter("gpsCode"); //GPS车载机上的对应编号
                String lineCount = request.getParameter("lineCode"); //配车/船数
                String category = request.getParameter("category"); //线路分类
                String circle = request.getParameter("circle"); //是否循环线路，0为非环线 1为环线
                String deptCode =request.getParameter("deptCode"); //部门编号(唯一标识符)
                String deptName = request.getParameter("deptName");//部门名称
                String companyCode = request.getParameter("companyCode"); // 公司编号(唯一标识符)
                String companyName = request.getParameter("companyName"); //公司名称

                if(!StringUtils.isNotBlank(appKey) && !StringUtils.isNotBlank(lineCode) && !StringUtils.isNotBlank(lineNo)
                        && !StringUtils.isNotBlank(lineName) && !StringUtils.isNotBlank(lineShort) && !StringUtils.isNotBlank(gpsCode)
                        && !StringUtils.isNotBlank(lineCount) && !StringUtils.isNotBlank(category) && !StringUtils.isNotBlank(circle)
                        && !StringUtils.isNotBlank(deptCode) && !StringUtils.isNotBlank(deptName) && !StringUtils.isNotBlank(companyCode)
                        && !StringUtils.isNotBlank(companyName)){
                    voStatus.setCode(0);
                    voStatus.setMessage("增加失败");
                    map.put("status",voStatus);
                    break;
                }
                voStatus.setCode(0);
                voStatus.setMessage("增加成功");
                map.put("status",voStatus);
            } while (false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
}
